package com.ruoyi.funding.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.funding.domain.FundingExpenditure;
import com.ruoyi.funding.service.IFundingExpenditureService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

import static com.ruoyi.common.security.utils.SecurityUtils.getUsername;

/**
 * 资金支出记录 Controller
 * 
 * @author ycl
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/expenditure")
public class FundingExpenditureController extends BaseController
{
    @Autowired
    private IFundingExpenditureService fundingExpenditureService;

    /**
     * 查询资金支出记录 列表
     */
    @RequiresPermissions("funding:expenditure:list")
    @GetMapping("/list")
    public TableDataInfo list(FundingExpenditure fundingExpenditure)
    {
        startPage();
        List<FundingExpenditure> list = fundingExpenditureService.selectFundingExpenditureList(fundingExpenditure);
        return getDataTable(list);
    }

    /**
     * 导出资金支出记录 列表
     */
    @RequiresPermissions("funding:expenditure:export")
    @Log(title = "资金支出记录 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FundingExpenditure fundingExpenditure)
    {
        List<FundingExpenditure> list = fundingExpenditureService.selectFundingExpenditureList(fundingExpenditure);
        ExcelUtil<FundingExpenditure> util = new ExcelUtil<FundingExpenditure>(FundingExpenditure.class);
        util.exportExcel(response, list, "资金支出记录 数据");
    }

    /**
     * 获取资金支出记录 详细信息
     */
    @RequiresPermissions("funding:expenditure:query")
    @GetMapping(value = "/{expenditureId}")
    public AjaxResult getInfo(@PathVariable("expenditureId") Long expenditureId)
    {
        return success(fundingExpenditureService.selectFundingExpenditureByExpenditureId(expenditureId));
    }

    /**
     * 新增资金支出记录 
     */
    @RequiresPermissions("funding:expenditure:add")
    @Log(title = "资金支出记录 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FundingExpenditure fundingExpenditure)
    {
        fundingExpenditure.setCreateBy(getUsername());
        return toAjax(fundingExpenditureService.insertFundingExpenditure(fundingExpenditure));
    }

    /**
     * 修改资金支出记录 
     */
    @RequiresPermissions("funding:expenditure:edit")
    @Log(title = "资金支出记录 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FundingExpenditure fundingExpenditure)
    {
        return toAjax(fundingExpenditureService.updateFundingExpenditure(fundingExpenditure));
    }

    /**
     * 删除资金支出记录 
     */
    @RequiresPermissions("funding:expenditure:remove")
    @Log(title = "资金支出记录 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expenditureIds}")
    public AjaxResult remove(@PathVariable Long[] expenditureIds)
    {
        return toAjax(fundingExpenditureService.deleteFundingExpenditureByExpenditureIds(expenditureIds));
    }
}
